package com.zhuangjie.mvc.validator.handler;

import com.zhuangjie.mvc.validator.annotate.Contains;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class ContainsValidator implements ConstraintValidator<Contains, String> {

    private String character;

    @Override
    public void initialize(Contains contains) {
        character = contains.value();
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return value != null && value.contains(character);
    }
}